// /*
//  * @Author: WanYiMing
//  * @Date:2024-07-05-11:15
//  * @Description:
//  */

using UnityEngine;

namespace Code.GameLogic.XianJian.Element.JianQiAction
{
    public class ActionSpaceLine:AbsJianQiAction
    {
        
        
        public override void ActionStart()
        {
            GameObject jianQi = JianQiActionData.JianQi;
            GameObject target = JianQiActionData.Target;
            Rigidbody2D rigidbody2D = JianQiActionData.Rigidbody2D;
            float speed = JianQiActionData.Speed;

            // 实例化子弹对象
            // 计算朝向目标的方向向量
            Vector3 direction = (target.transform.position - jianQi.transform.position).normalized;
            direction.z = 1f; // 将Z轴设置为，保持在XY平面上
            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            // 进行旋转
            Quaternion targetRotation = Quaternion.Euler(0, 0, angle);
            // 旋转子弹使其朝向目标
            jianQi.transform.rotation = targetRotation;

            // 设置子弹的速度和方向，可以给子弹添加刚体组件并使用它的力或速度属性来移动子弹
            rigidbody2D.velocity = direction * speed; // 子弹速度为10

        }

        public override bool ActionHolding()
        {
            return JianQiActionData.ActiveTime<3;
        }

        public override void ActionExit()
        {
            
        }
    }
}